package cn.nexd.location.indoor;

import android.content.Context;

import cn.nexd.location.indoor.core.IndoorLocationProxySubject;
import cn.nexd.location.indoor.listener.NexdIndoorLocationListener;

/**
 * Nexd 室内定位的入口函数类. 此类为单例类.
 */
public class NexdIndoorLocationAgent {

    static {
        System.loadLibrary("location_engine");
    }

    private static IndoorLocationProxySubject indoorLocationProxySubject;

    private NexdIndoorLocationAgent() {
    }

    /**
     * 获取 NexdIndoorLocationAgent 实例
     *
     * @return NexdIndoorLocationAgent
     */
    public static NexdIndoorLocationAgent getIndoorLocationAgent(Context context) {
        indoorLocationProxySubject = new IndoorLocationProxySubject(context);
        return NexdIndoorLocationAgentClassHolder.NEXD_INDOOR_LOCATION_AGENT;
    }

    public void setIndoorLocationConfiguration(final NexdIndoorLocationConfiguration indoorLocationConfiguration) {
        indoorLocationProxySubject.setIndoorLocationConfiguration(indoorLocationConfiguration);
    }


    public void setIndoorLocationListener(NexdIndoorLocationListener indoorLocationListener) {
        indoorLocationProxySubject.setIndoorLocationListener(indoorLocationListener);
    }

    public void startLocation() {
        indoorLocationProxySubject.startLocation(-1L, -1L);
    }

    public void startLocation(long buildingId, long floorId) {
        indoorLocationProxySubject.startLocation(buildingId, floorId);
    }

    public void startLocation(long buildingId) {
        indoorLocationProxySubject.startLocation(buildingId, -1L);
    }


    public void stopLocation() {
        indoorLocationProxySubject.stopLocation();
    }

    public void destroyLocation() {
        indoorLocationProxySubject.destroyLocation();
    }

    private static class NexdIndoorLocationAgentClassHolder {
        private static final NexdIndoorLocationAgent NEXD_INDOOR_LOCATION_AGENT = new NexdIndoorLocationAgent();
    }
}
